// This file is released under the terms of the GNU General Public License v3.
// Copyright 2011  Danila Bespalov <danila.bespalov@gmail.com>,
//                 Gleb Devlikamov <onclip@gmail.com>
//
// Dealing with input devices.

#include "GameLib.h"


void CGame::ProcessEvents()
{
	
	const float mouse_factor = 0.32;
	SDL_Event event;
	while(SDL_PollEvent(&event))
	{
		switch(event.type)
		{
		case SDL_QUIT:
			game_stop = true;
			break;
		case SDL_MOUSEMOTION:
			
			break;
		case SDL_MOUSEBUTTONUP:
			if(event.button.button == SDL_BUTTON_LEFT)
			{
				
			}
			break;
		case SDL_KEYDOWN:
			SDLMod mod = SDL_GetModState();
			switch(event.key.keysym.sym)
			{
			case SDLK_ESCAPE:
				game_stop = true;
				break;
			case SDLK_m:
				//sound.PlaySound();
				break;
			case SDLK_f:
				if(glIsEnabled(GL_LIGHTING))
				{
					glDisable(GL_LIGHTING);
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
				}
				else
				{
					glEnable(GL_LIGHTING);
					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
				}
				break;
			case SDLK_F4:
				break;
			case SDLK_r:
				SDL_GL_SwapBuffers();
				break;
			case SDLK_n:
				
				break;
			case SDLK_0:

				break;
			case SDLK_1:
				
				break;
			case SDLK_2:

				break;
			case SDLK_3:
				
				break;
			case SDLK_4:
				
				break;
			}
			break;
		}
	}

/*	Uint8* kb_state = SDL_GetKeyState(NULL);
	const float speed = 0.085;

	if(kb_state[cfg.keys[MOVE_FORTH]])
	{
		
	}
	if(kb_state[cfg.keys[MOVE_BACK]])
	{
		
	}
	if(kb_state[cfg.keys[MOVE_RIGHT]])
	{
		
	}
	if(kb_state[cfg.keys[MOVE_LEFT]])
	{
		
	}*/
}


// TODO: We're of course better off using enum instead of plain integer, and
// also placing this function in ThePlayer is somewhat questionable.
/*void ThePlayer::ChangeLight(int n)
{
	GLfloat l_none[] = { 0.0, 0.0, 0.0, 1.0 };
	GLfloat l_full[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat l_yellowish[] = { 1.0, 0.94, 0.86, 1.0 };
	switch(n)
	{
	case 0:
		glLightfv(GL_LIGHT0, GL_DIFFUSE, l_none);
		break;
	case 1:
	case 2:
		glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.12);
		glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.011);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, l_full);
		glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45);
		glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 34);
		break;
	}
}*/